/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package d.colegio.view;

import d.colegio.model.Alumno;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 *
 * @author 15031598-0
 */
public class ListaNotas extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        List notas= new ArrayList();
        
        
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            notas.add(new Alumno("111", "Juan", "Perez", "Masculino", "Matemáticas", "1.2", "5.4", "7.0"));
            notas.add(new Alumno("222", "Vanesa", "Heinz", "Femenino", "Física", "3.4", "6.5", "5.7"));
            notas.add(new Alumno("333", "Maximo", "Hess", "Masculino", "Lenguaje", "6.0", "6.0", "7.0"));
            
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Lista de Notas</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<table border='2'");
            out.println("<th>");
            out.println("<td>Rut</td>");
            out.println("<td>Nombres</td>");
            out.println("<td>Apellidos</td>");
            out.println("<td>Sexo</td>");
            out.println("<td>Asignatura</td>");
            out.println("<td>Nota 1</td>");
            out.println("<td>Nota 2</td>");
            out.println("<td>Nota 3</td>");
            out.println("<td>Promedio</td>");
            out.println("</th>");
            
            Iterator contenido = notas.iterator();
            
            while (contenido.hasNext())
            {
                Alumno getcontenido = (Alumno) contenido.next();

                out.println("<tr>");
                out.println("<td>"+getcontenido.getRut()+"</td>");
                out.println("<td>"+getcontenido.getNombres()+"</td>");
                out.println("<td>"+getcontenido.getApellidos()+"</td>");
                out.println("<td>"+getcontenido.getSexo()+"</td>");
                out.println("<td>"+getcontenido.getAsignatura()+"</td>");
                out.println("<td>"+getcontenido.getN1()+"</td>");
                out.println("<td>"+getcontenido.getN2()+"</td>");
                out.println("<td>"+getcontenido.getN3()+"</td>");
                out.println("<td>"+String.valueOf(getcontenido.calculopromedio())+"</td>");
                out.println("</tr>");
            }
            
            
            out.println("</table>");
            
            out.println("<ul>");
            out.println("<li><a href='/Colegio'>Volver al Inicio</a></li>");
            out.println("</ul>");
            
            
            out.println("</body>");
            out.println("</html>");
        }
    }
       
    

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
